// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init({
  env: cloud.DYNAMIC_CURRENT_ENV
})

// 云函数入口函数
exports.main = async (event, context) => {
  try {
    const { fileID } = event
    
    if (!fileID) {
      return {
        success: false,
        error: 'fileID is required'
      }
    }
    
    // 设置文件为公有读取权限
    const result = await cloud.openapi.cloudbase.setFileAccess({
      fileList: [{
        fileID: fileID,
        access: 'public'
      }]
    })
    
    return {
      success: true,
      result
    }
  } catch (err) {
    return {
      success: false,
      error: err
    }
  }
} 